package com.coolw.spring.config;

import com.coolw.spring.filter.MyFilter;
import com.coolw.spring.filter.MyFilter2;
import com.google.common.collect.Lists;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 过滤器配置
 *
 * @author coolw
 * @date 2025/5/12 19:43
 */
@Configuration
public class WebFilterConfig {

    @Bean
    public FilterRegistrationBean myFilterRegistration() {
        FilterRegistrationBean bean = new FilterRegistrationBean();
        bean.setFilter(myFilter());
        bean.setUrlPatterns(Lists.newArrayList("/auth/*"));
        // 过滤器执行顺序，值越小越先执行
        bean.setOrder(0);
        return bean;
    }

    @Bean
    public FilterRegistrationBean myFilter2Registration() {
        FilterRegistrationBean bean = new FilterRegistrationBean();
        bean.setFilter(myFilter2());
        bean.setUrlPatterns(Lists.newArrayList("/auth/*"));
        // 过滤器执行顺序，值越小越先执行
        bean.setOrder(5);
        return bean;
    }

    @Bean
    public MyFilter myFilter() {
        return new MyFilter();
    }

    @Bean
    public MyFilter2 myFilter2() {
        return new MyFilter2();
    }
}
